#include <iostream>
#include <vector>

bool FindNumber(int *numbers, int num, int rows, int columns)
{
    // 判空 or 行数为0 or 列数为0
    if (numbers == nullptr || rows <= 0 || columns <= 0)
        return false;

    // 查找
    int row = 0;
    int column = columns - 1;
    while(row < rows && column >= 0)
    {
        //找到了
        if(numbers[row * columns + column] == num)
            return true;
        //元素比num小
        if(numbers[row * columns + column] < num)
            row++;
        //元素比num大
        else
            column--;
    }
    return false;
}

int main()
{
    int number[16] = {1, 2, 8, 9, 2, 4, 9, 12, 4, 7, 10, 13, 6, 8, 11, 15};
    std::cout << FindNumber(number, 1, 4, 4) << std::endl;
    std::cout << FindNumber(number, 100, 4, 4) << std::endl;
    std::cout << FindNumber(number, -1, 4, 4) << std::endl;
    std::cout << FindNumber(number, 3, 4, 4) << std::endl;
    std::cout << FindNumber(number, 5, 4, 4) << std::endl;
    std::cout << FindNumber(number, 10, 4, 4) << std::endl;
    return 0;
}